import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @USER: Administrator
 * @DATE: 2024/9/15 下午12:27
 * @VERSION: 1.0.0
 */
public class LC1365 {
    public static void main(String[] args) {
        LC1365 lc1365 = new LC1365();
        int[] nums = new int[]{8,1,2,2,3};
        System.out.println(Arrays.toString(lc1365.smallerNumbersThanCurrent(nums)));
    }

    public int[] smallerNumbersThanCurrent(int[] nums) {
        // 结果
        int[] result = new int[nums.length];

        // 把原数组的数据存到集合里
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }

        // 对原数组排序
        Arrays.sort(nums);

        for (int i = 0; i < list.size(); i++) {
            for (int k = 0; k < nums.length; k++) {
                if (list.get(i) == nums[k]) {
                    result[i] = k;
                    break;
                }
            }
        }


        return result;
    }

}
